DIRECTIONS = {d: i for (i, d) in enumerate(["N", "E", "S", "W"])}
MOVE = [(0, -1), (1, 0), (0, 1), (-1, 0)]
ROTX = [(1, 0), (0, -1), (-1, 0), (0, 1)]
ROTY = [(0, 1), (1, 0), (0, -1), (-1, 0)]

with open('input.txt') as file:
    x, y, d = 0, 0, DIRECTIONS["E"]
    
    for line in file.readlines():
        op, arg = line[0], int(line[1:])

        if op == "R":
            d = (d + arg // 90) % 4
        elif op == "L":
            d = (d - arg // 90) % 4
        else:
            dx, dy = MOVE[DIRECTIONS.get(op, d)]
            x += dx * arg
            y += dy * arg

    print(abs(x) + abs(y))